﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PO_2011;



namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {

        private Pnm p;
        public Form1 refToMainWindow;

        public Form2(Pnm objectPnm)
        {
            InitializeComponent();
            p = objectPnm;
        }

        //zdarzenie Click Kanał L
        private void lChannelradioButton_Click(object sender, EventArgs e)
        {
            //wywołanie procedury ComputeHistogram dla Kanału L
            //ustawienie nowej bitmapy - nowy histogram
            //muszę mieć obiekt klasy Pnm i na nim wywołac procedure
            p.ComputeHistogramL();
            if (this.cummulatedRadioButton.Checked == true)
                p.ComputeCummulatedHistogram();
            this.pictureBoxHistogram.Image = p.HistogramBitmap;
            
        }

        private void rChannelradioButton_Click(object sender, EventArgs e)
        {
            p.ComputeHistogramR();
            if (this.cummulatedRadioButton.Checked == true)
                p.ComputeCummulatedHistogram();
            this.pictureBoxHistogram.Image = p.HistogramBitmap;
        }

        private void gChannelradioButton_Click(object sender, EventArgs e)
        {
            p.ComputeHistogramG();
            if (this.cummulatedRadioButton.Checked == true)
                p.ComputeCummulatedHistogram();
            this.pictureBoxHistogram.Image = p.HistogramBitmap;
        }

        private void bChannelradioButton_Click(object sender, EventArgs e)
        {
            p.ComputeHistogramB();
            if (this.cummulatedRadioButton.Checked == true)
                p.ComputeCummulatedHistogram();
            this.pictureBoxHistogram.Image = p.HistogramBitmap;
        }

        private void cummulatedRadioButton_Click(object sender, EventArgs e)
        {
            if (this.lChannelradioButton.Checked)
                this.lChannelradioButton_Click(sender, e);

            if (this.rChannelradioButton.Checked)
                this.rChannelradioButton_Click(sender, e);

            if (this.gChannelradioButton.Checked)
                this.gChannelradioButton_Click(sender, e);

            if (this.bChannelradioButton.Checked)
                this.bChannelradioButton_Click(sender, e);


        }

        private void normalRadioButton_Click(object sender, EventArgs e)
        {
            if (this.lChannelradioButton.Checked)
                this.lChannelradioButton_Click(sender, e);

            if (this.rChannelradioButton.Checked)
                this.rChannelradioButton_Click(sender, e);

            if (this.gChannelradioButton.Checked)
                this.gChannelradioButton_Click(sender, e);

            if (this.bChannelradioButton.Checked)
                this.bChannelradioButton_Click(sender, e);
        }

        public void equalizationButton_Click(object sender, EventArgs e)
        {
            int type = p.getTypeOfFile();
            if((type != 1)&&(type != 4))
                {
                    if (this.rChannelradioButton.Checked)
                    {
                        p.ComputeHistogramR();
                        p.ComputeCummulatedHistogram();
                        p.Equalize();
                    }
                    if (this.gChannelradioButton.Checked)
                    {
                        p.ComputeHistogramG();
                        p.ComputeCummulatedHistogram();
                        p.Equalize();
                    }

                    if (this.bChannelradioButton.Checked)
                    {
                        p.ComputeHistogramB();
                        p.ComputeCummulatedHistogram();
                        p.Equalize();
                    }
                    

                    this.refToMainWindow.pictureBox1.Image = p.Bitmap;
                    if (this.rChannelradioButton.Checked)
                        p.ComputeHistogramR();
                    if (this.gChannelradioButton.Checked)
                        p.ComputeHistogramG();
                    if (this.bChannelradioButton.Checked)
                        p.ComputeHistogramB();
                    p.ComputeCummulatedHistogram();


                    #region narysuj histogram
                    if (this.lChannelradioButton.Checked)
                        this.lChannelradioButton_Click(sender, e);

                    if (this.rChannelradioButton.Checked)
                        this.rChannelradioButton_Click(sender, e);

                    if (this.gChannelradioButton.Checked)
                        this.gChannelradioButton_Click(sender, e);

                    if (this.bChannelradioButton.Checked)
                        this.bChannelradioButton_Click(sender, e);
                    #endregion

                }
            
        }

        public void strechHistogramButton_Click(object sender, EventArgs e)
        {
            int type = p.getTypeOfFile();
            if ((type != 1) && (type != 4))
            {
                if (this.rChannelradioButton.Checked)
                {
                    p.ComputeHistogramR();
                    p.ComputeCummulatedHistogram();
                    p.Strech();
                }
                if (this.gChannelradioButton.Checked)
                {
                    p.ComputeHistogramG();
                    p.ComputeCummulatedHistogram();
                    p.Strech();
                }
                if (this.bChannelradioButton.Checked)
                {
                    p.ComputeHistogramB();
                    p.ComputeCummulatedHistogram();
                    p.Strech();
                }

                this.refToMainWindow.pictureBox1.Image = p.Bitmap;
                if (this.rChannelradioButton.Checked)
                    p.ComputeHistogramR();
                if (this.gChannelradioButton.Checked)
                    p.ComputeHistogramG();
                if (this.bChannelradioButton.Checked)
                    p.ComputeHistogramB();
                p.ComputeCummulatedHistogram();
                #region narysuj histogram
                if (this.lChannelradioButton.Checked)
                    this.lChannelradioButton_Click(sender, e);

                if (this.rChannelradioButton.Checked)
                    this.rChannelradioButton_Click(sender, e);

                if (this.gChannelradioButton.Checked)
                    this.gChannelradioButton_Click(sender, e);

                if (this.bChannelradioButton.Checked)
                    this.bChannelradioButton_Click(sender, e);
                #endregion
            }
        }

    }
}
